﻿/*
 * ======================================================================
 *                           Modern Warfare3 Launcher
 * Copyright 2011-2012
 * Developer:Pooya parsa
 * Email:pingsft@gmail.com
 * You are ALLOWED:
 * -Read source code
 * -Use some part of source code with Full name and email of developer
 * -Release your own mod with name of develepor
 * You are NOT ALLOWD:
 * -Add cracked version of Mw3
 * -Release modified version as MW3Launcher
 * -Mirror Sourcecode
 * -Use source code without name of developer
 * Thank you for your attention
 * ======================================================================
 * */
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace MW3Launcher
{
    static class Program
    {
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool SetForegroundWindow(IntPtr hWnd);
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            
            bool createdNew = true;
            Mutex mutex = new Mutex(true, "Mw3Launcher", out createdNew);
            if (!createdNew)
            {
               
                Process current = Process.GetCurrentProcess();
                foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                {
                    if (process.Id != current.Id)
                    {
                        //SetForegroundWindow(process.MainWindowHandle);
                        try { ;process.Kill(); }catch { }
                        break;
                    }
                }
            }



            if (args.Length > 0)
            {
                //Console mode
                //Make mainwindow withou show
                MainWindow a = new MainWindow();
                //a.MainWindow_Load(null, null);
                switch (args[0].ToUpper())
                {
                    case "MP":
                        a.btnMPLAN_Click(null, null);
                        break;
                    case "SPC":
                        a.BtnSpc_Click(null, null);
                        break;
                    case "SPH":
                        a.btnSPH_Click(null, null);
                        break;
                    case "SETTINGS":
                        Application.Run(new Settings());
                        break;
                }
            }
            else
            {
                //GUI mode
                Application.Run(new MainWindow());
            }
        }
    }
}
